#!/bin/dash
# Use ShellCheck: https://www.shellcheck.net/
# shellcheck disable=SC2034 # Ignore unused variables

# This file is loaded by "/etc/init.d/kurento-media-server", the system service
# init script that is run by the command `service kurento-media-server start`.
#
# Settings found in this file won't be loaded if Kurento Media Server is started
# manually, for example by directly executing `/usr/bin/kurento-media-server`.



# Service init script settings
# ============================

# If not "true", the service will refuse to start
START_DAEMON="true"

# Arguments that will get passed directly to the KMS executable
DAEMON_ARGS=""

# Linux user that will be owner of KMS process and generated files
DAEMON_USER="kurento"

## System-wide destination of Kernel core dump files. See:
## https://www.kernel.org/doc/Documentation/sysctl/kernel.txt
##
## Note that in Ubuntu with Apport the default pattern is:
##     |/usr/share/apport/apport %p %s %c %d %P
## and it only creates a one-time Crash Report in "/var/crash/". See:
## https://doc-kurento.readthedocs.io/en/latest/user/troubleshooting.html#media-server-crashes
##
## Uncomment this to override Apport and/or set a custom core dump destination
## into the file "/proc/sys/kernel/core_pattern":
#DAEMON_CORE_PATTERN="/tmp/core_%e_%p_%u_%t"

## Per-process max open file descriptors (set to half of system-wide max)
## Only touch this if you are a sysadmin and/or you know what you are doing!
DAEMON_MAX_FILES="$(( $(cat /proc/sys/fs/file-max) / 2 ))"

## Per-user max threads (set to Kernel hard limit)
## Only touch this if you are a sysadmin and/or you know what you are doing!
## Note: This is '-u' in Bash and '-p' in POSIX shell (like Dash)
#DAEMON_MAX_THREADS="$(ulimit -Hp)"



# Debug & logging settings
# ========================

## Default recommended logging levels
export GST_DEBUG="2,Kurento*:4,kms*:4,sdp*:4,webrtc*:4,*rtpendpoint:4,rtp*handler:4,rtpsynchronizer:4,agnosticbin:4"

## Extended logging
##
## To investigate issues in some parts of KMS, you'll want to enable additional
## logs. Check out KMS docs to see some of the **suggested levels**:
## https://doc-kurento.readthedocs.io/en/latest/features/logging.html
##
## For convenience, some of the suggested levels are provided here:
##
## Extended logging: MediaFlow{In,Out} event state changes
#export GST_DEBUG="${GST_DEBUG:-2},KurentoMediaElementImpl:5"
##
## Extended logging: WebRTC ICE candidate gathering
#export GST_DEBUG="${GST_DEBUG:-2},webrtcendpoint:5,kmswebrtcsession:5,kmsiceniceagent:5"
##
## Extended logging: Transcoding of media
#export GST_DEBUG="${GST_DEBUG:-2},KurentoMediaElementImpl:5,agnosticbin*:5"

## Disable colored output, so logs don't contain extraneous characters
export GST_DEBUG_NO_COLOR="1"

## Output path for GStreamer debug graphs (uncomment to enable graphs)
#export GST_DEBUG_DUMP_DOT_DIR="/tmp"

## Path where to store log files
export KURENTO_LOGS_PATH="/var/log/kurento-media-server"

## Maximum file size for rotating log files, in MB (default: 100 MB)
#export KURENTO_LOG_FILE_SIZE=100

## Maximum number of rotating log files to keep (default: 10 files)
#export KURENTO_NUMBER_LOG_FILES=10

## Abort the server when underlying libs print a Warning or Critical message,
## for example "GStreamer-WARNING" or "GStreamer-CRITICAL". This can be used to
## obtain a Kernel core dump or a GDB backtrace, needed to solve the issue. See:
## https://doc-kurento.readthedocs.io/en/latest/user/troubleshooting.html#gstreamer-critical-messages-in-the-log
#export G_DEBUG="fatal-warnings"



# Advanced server settings
# ========================

unset GST_PLUGIN_PATH

## Path to the main configuration file for Kurento Media Server
#export KURENTO_CONF_FILE="/etc/kurento/kurento.conf.json"

## Path to the directory where Kurento modules can be found
#export KURENTO_MODULES_PATH="/usr/lib"

## Path to the directory where config files can be found for Kurento modules
#export KURENTO_MODULES_CONFIG_PATH="/etc/kurento/modules"
